Git Credentials: Refactor deletion logic [INS-2471]#9906
Open
yaoweiprc wants to merge 1 commit into
Open
Conversation
…projects by user organization
✅ Circular References ReportGenerated at: 2026-05-07T10:30:02.716Z Summary
Click to view all circular references in PR (19)Click to view all circular references in base branch (19)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Git credential deletion flow to (1) avoid blocking deletion due to projects the current user doesn’t own and (2) ensure connected git repositories are properly unlinked/removed when a credential is deleted.
Changes:
- Filters “related projects” for a credential to only those owned by the current user’s organizations (plus scratchpad).
- Exports the git-repository removal helper from
session.tsfor reuse. - Deletes connected git repositories (and unlinks projects/workspace metas) when deleting a credential, instead of only nulling
credentialsId.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx | Filters related projects by current user org ownership before returning them to the UI. |
| packages/insomnia/src/routes/git-credentials.$id.delete.tsx | Uses _removeGitRepository to fully unlink/remove repos when deleting a credential. |
| packages/insomnia/src/account/session.ts | Exposes _removeGitRepository for use outside the session module. |
Comments suppressed due to low confidence (1)
packages/insomnia/src/account/session.ts:235
_removeGitRepositorydeletes the repository record directly, but unlikeresetGitRepoAction(main process) it does not stoprepoFileWatcherRegistryor clear conflict suppression. Now that this helper is used outside logout (e.g., credential deletion), consider coordinating with the main-process git service (via IPC) to ensure watchers are stopped and any per-repo state is cleaned up when a repo is removed.
export async function _removeGitRepository(repo: GitRepository) {
const queryIds = models.project.getQueryableGitRepositoryIds(repo._id);
const projects = await database.find<Project>(models.project.type, { gitRepositoryId: { $in: queryIds } });
for (const p of projects) {
await services.project.update(p, { gitRepositoryId: models.project.EMPTY_GIT_PROJECT_ID });
}
const workspaceMetas = await database.find<WorkspaceMeta>(models.workspaceMeta.type, { gitRepositoryId: repo._id });
for (const wsMeta of workspaceMetas) {
await services.workspaceMeta.update(wsMeta, { gitRepositoryId: null });
}
await services.gitRepository.remove(repo);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+18
to
+26
| const { accountId } = await services.userSession.getOrCreate(); | ||
| const organizations = JSON.parse(localStorage.getItem(`${accountId}:organizations`) || '[]') as Organization[]; | ||
| const currentUserOrganizationIds = new Set([ | ||
| ...organizations.map(o => o.id), | ||
| models.organization.SCRATCHPAD_ORGANIZATION_ID, | ||
| ]); | ||
|
|
||
| const currentUserProjects = relatedProjects.filter(p => currentUserOrganizationIds.has(p.parentId)); | ||
|
|
Comment on lines
16
to
20
| const connectedRepositories = await services.gitRepository.getAllByCredentialId(id); | ||
|
|
||
| for (const repo of connectedRepositories) { | ||
| await services.gitRepository.update(repo, { credentialsId: null }); | ||
| await _removeGitRepository(repo); | ||
| } |
Comment on lines
+223
to
225
| export async function _removeGitRepository(repo: GitRepository) { | ||
| const queryIds = models.project.getQueryableGitRepositoryIds(repo._id); | ||
| const projects = await database.find<Project>(models.project.type, { gitRepositoryId: { $in: queryIds } }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two bugs existed in the Git credential deletion flow:
1. False "Cannot Delete Git Credential" warning
When deleting a Git credential, the app checks whether any projects are linked to it via a
GitRepository. If linked projects are found, it blocks deletion and shows a warning listing those projects.However, the query returned all linked projects regardless of ownership. A project belonging to a different user (i.e., whose
parentIdis not in the current user's organizations) would still appear in the list, causing the warning to fire — even though the current user cannot see or manage that project.2. Incomplete cleanup on credential deletion
When a credential was deleted, the action only set
credentialsId: nullon connectedGitRepositoryrecords, leaving the repositories intact and still linked to their associated projects and workspace metas. This left those projects in a broken git state.Changes
git-credentials.$id.related-projects.tsx: After fetching projects linked to a credential's repositories, filter them to only include projects whoseparentIdbelongs to the current user's organizations (matching the same ownership check used inuntrackedProjects). Projects owned by other users are excluded, so they no longer trigger the deletion warning.session.ts: Exported the existing_removeGitRepositoryhelper so it can be reused outside the module.git-credentials.$id.delete.tsx: On credential deletion, call_removeGitRepositoryfor each connected repository instead of only nullingcredentialsId. This properly unlinks the repository from associated projects (resettinggitRepositoryIdtoEMPTY_GIT_PROJECT_ID) and workspace metas before removing the repository record.